<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui">

<ui:composition template="/template.xhtml">

	<ui:define name="title">
		Registrar Pedido
	</ui:define>

	<ui:define name="content">

		<h:form id="registrarPedidoForm">

			<p:panel id="panel" header="Registrar Pedido"
				style="margin-top:auto; margin-bottom:auto; width:90%; margin-left: auto; margin-right: auto;">

				<p:messages id="messages" />

				<h:panelGrid columns="4">

					<h:outputLabel for="comandaInput" value="Comanda*: " />
					<p:inputMask id="comandaInput" value="#{pedidoBean.comanda}"
						required="true" mask="9?9999999" maxlength="8"
						requiredMessage="Obrigatório o fornecimento do número da comanda!"
						converterMessage="Número de comanda inválido!">
						<f:converter converterId="comandaConverter" />
					</p:inputMask>

					<h:outputLabel for="mesaSelect" value="Mesa: " />
					<p:selectOneMenu id="mesaSelect" value="#{pedidoBean.mesaId}">
						<f:selectItem itemLabel="" itemValue="" />
						<f:selectItems value="#{pedidoBean.mesas}" var="m"
							itemLabel="#{m.dsMesa}" itemValue="#{m.idMesa}" />
					</p:selectOneMenu>

				</h:panelGrid>

				<h:panelGrid id="itemGrid" columns="6">

					<h:outputLabel for="itemAutoComplete" value="Item*: " />
					<p:autoComplete id="itemAutoComplete" value="#{pedidoBean.item}"
						var="item" itemLabel="#{item.itemLabel}" converter="itemConverter"
						itemValue="#{item}" queryDelay="300"
						completeMethod="#{pedidoBean.completeItem}" forceSelection="true">
						<p:ajax update="quantidadeSpinner" />
					</p:autoComplete>

					<h:outputLabel for="quantidadeSpinner" value="Quantidade *" />
					<p:spinner id="quantidadeSpinner" value="#{pedidoBean.quantidade}"
						stepFactor="#{pedidoBean.item.unidadeMedida.flDiscreto == '1' ? 1 : 0.01}"
						required="true" min='0' />

				</h:panelGrid>
				<h:outputLabel for="observacoesArea" value="Observações: " />
				<p:inputTextarea rows="5" style="width:90%"
					value="#{pedidoBean.observacoes}" />
				<h:panelGrid columns="2">

				</h:panelGrid>

				<p:commandButton value="Registrar Pedido"
					actionListener="#{pedidoBean.registrarPedido}" update="panel" />

			</p:panel>

		</h:form>

	</ui:define>
</ui:composition>

</html>